package com.mukefile.interceptor;

import com.mukefile.pojo.Manager;
import com.mukefile.pojo.User;
import com.mukefile.utils.constant.Constant;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import java.util.Map;

/**
 * @Author: kenewstar
 * @Description: 登录拦截器
 * @Date:Created in 2020/5/21
 */
public class MyInterceptor extends MethodFilterInterceptor {


    @Override
    public String doIntercept(ActionInvocation invocation) throws Exception {
        //获取用户是否登录
        //获取Session
        Map<String,Object> session = ActionContext.getContext().getSession();
        //获取用户
        User user = (User)session.get(Constant.SESSION_USER);
        Manager manager = (Manager)session.get("manager");
        if (user!=null||manager!=null){
            //只要有一个不等于null，则表示用户登录
            return invocation.invoke();
        }
        //未登录
        return "login";
    }
}
